<?php
class CategoryController extends Bib_Controller_Action {
	public function browseCategoriesAction()
	{
		$manager = CategoryManager::getInstance();
		$id = $this->_getParam('id', 0);
		
		if ($id) {
			$categories = $manager->getById($id)->getChildren();
		} else {
			$categories = $manager->getRoot()->getChildren();
		}
						
		$this->view->categories = $categories;
	}
	
	public function showCategoriesAction()
	{
		$manager = CategoryManager::getInstance();
		$categories = $manager->getRoot()->getDescendants();
						
		$this->view->categories = $categories;
	}
	
	public function showCategoryAction()
	{
		$manager = CategoryManager::getInstance();
		
		$id = $this->_getParam('id', 0);
		$category = $manager->getById($id);
						
		$this->view->category = $category;
	}

	public function deleteAction() 
	{
		$id = $this->_getParam('id');
		
		$cat = CategoryManager::getInstance()->getById($id);
		CategoryManager::getInstance()->deleteBranch($cat);
		
		$this->view->infoBox();
		$this->view->message = "Kategoria usunięta.";
		$this->view->redirect = 'javascript:history.back()';
	}
}